package net.comm.param.db;

import org.sakaiproject.db.api.iServiceSql;


/**
 * methods for accessing user data in a database.
 */
public class CnpcaServiceSqlMysql implements iServiceSql
{
	/**
	 * 返回根据主键删除语句
	 */
	public String getDeleteSql()
	{
		return "delete from Cnpca where Id=?";
	}

	/**
	 * 返回插入语句
	 */
	public String getInsertSql()
	{
		return "insert into Cnpca ( id, name,  pid,  cid )" +
				" values (?,?,?,?)";
	}
	
	/**
	 * 返回根据主键修改语句
	 */
	public String getUpdateSql()
	{
		return "update Cnpca  set name=?,  pid=?,  cid=? " +
				" where Id=? ";
	}

	/**
	 * 返回根据主键查询语句
	 */
	public String getbykeySql()
	{
		return "select  id, name,  pid,  cid " +
				" from Cnpca where Id=? ";
	}
	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecSql()
	{
	
		StringBuffer sb =  new StringBuffer("select id, name,  pid,  cid ");
		sb.append(" from Cnpca ");
				
		return sb.toString();	
	}	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecbyPidSql()
	{
	
		StringBuffer sb =  new StringBuffer("select  id, name,  pid,  cid ");
		sb.append(" from Cnpca ");
		sb.append(" where pid=? and (cid=0 or cid = pid)");
				
		return sb.toString();	
	}	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecbyCidSql()
	{
	
		StringBuffer sb =  new StringBuffer("select  id, name,  pid,  cid ");
		sb.append(" from Cnpca ");
		sb.append(" where pid not in(0) and cid=? and cid not in (0)");
				
		return sb.toString();	
	}	
	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecbyNameSql()
	{
	
		
		StringBuffer sb =  new StringBuffer("select  id, name,  pid,  cid ");
		
		sb.append(" from Cnpca  where name=?  Order by name limit 0,1 ");
				
		return sb.toString();	
	}
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecbyPageSql()
	{
	
		StringBuffer sb =  new StringBuffer("select  assortID,  propID,  propname, assortname,  parentID, disNO, " +
				" exichiflag, userID,  mTime ");
		
		sb.append(" from Cnpca  where 1=1  limit ?,? ");
				
		return sb.toString();	
	}
	
	/**
	 * 返回所有记录数
	 */
	public String getCountSql1()
	{
		return "select count(*) as COUNT from Cnpca ";
	}


	/**
	 * 返回根据查询条件的记录数
	 */
	public String getCountSql2()
	{
		return null;
	}

	/**
	 * @see net.comm.job.db.iServiceSql.impl.UserServiceSql#getMaxInputsForSelectWhereInQueries()
	 */
	public int getMaxInputsForSelectWhereInQueries() {
		// For Oracle, the maximum supported number of expressions in a list is 1000. 
		return 1000;
	}
}
